package echat.future.cn.echat.my.weight.dialog;

import android.app.Dialog;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import echat.future.cn.echat.R;
import echat.future.cn.echat.databinding.DialogChoosePicBinding;

public class ChoosePicDialog extends Dialog{
    public ChoosePicDialog(@NonNull Context context) {
        this(context, R.style.bootomDialog);
    }

    public ChoosePicDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }


    public static class Builder{
        private Dialog dialog;
        private Context mContext;
        private String context;
        private View.OnClickListener cameroListenter;
        private View.OnClickListener photoListenter;
        private String takePhotoString;//拍照字样
        private int cancelColor = -1;
        private int confirmColor =  -1;
        public Builder(Context context){
            this.mContext = context;
        }

        public ChoosePicDialog.Builder content(String hintString){
            this.context = hintString;
            return this;
        }

        public ChoosePicDialog.Builder cameroListenter(View.OnClickListener onClickListener){
            this.cameroListenter = onClickListener;
            return this;
        }

        public ChoosePicDialog.Builder photoListenter(View.OnClickListener onClickListener){
            this.photoListenter =onClickListener;
            return this;
        }
        public ChoosePicDialog.Builder photoString(String takePhoto){
            this.takePhotoString =takePhoto;
            return this;
        }




        public Dialog Builder(){
            DialogChoosePicBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mContext),R.layout.dialog_choose_pic,null,false);
            binding.camera.setOnClickListener(cameroListenter);
            binding.phone.setOnClickListener(photoListenter);
            binding.cancel.setOnClickListener(v -> dialog.dismiss());
            if(context!=null)
                binding.title.setText(context);
            if(takePhotoString!=null){
                binding.camera.setText(takePhotoString);
            }
            dialog = new ChoosePicDialog(mContext);
            dialog.setContentView(binding.getRoot());
            Window window = dialog.getWindow();
            window.setGravity(Gravity.BOTTOM);

            WindowManager m = window.getWindowManager();
            Display d = m.getDefaultDisplay(); //为获取屏幕宽、高
            WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); //获取对话框当前的参数值
            p.width = WindowManager.LayoutParams.MATCH_PARENT;
            p.height = WindowManager.LayoutParams.WRAP_CONTENT;
            dialog.getWindow().setAttributes(p); //设置生效
            dialog.setCancelable(false);
            return dialog;
        }

    }
}
